using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BirthRandom : MonoBehaviour
{
    
    public typeOfBirth type;
    public List<GameObject> objects = new List<GameObject>();
    private void Start()
    {
        EventCenter.GetInstance().AddEventListener("BirthRandomInit",init);
    }
    public void init()
    {
        gameManager.instance.birthInit(type, this.gameObject);
    }
    public void random()
    {
        Vector2 a = transform.localScale;
        Vector2 b = objects[(int)type].transform.localScale;
        Vector2 c = a - b;

        float x, y;
        x = GetRandomNumber(-c.x / 2, c.x/2);
        y = GetRandomNumber(-c.y / 2, c.y/2);
        Debug.Log( c+" "+x + " " + y);
        Vector3 d = new Vector2(transform.position.x + x, transform.position.y - y);
        Quaternion quaternion = Quaternion.Euler(0, 0, 0);
        Instantiate(objects[(int)type], d, quaternion);
    }
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.M))
        {
            random();
        }
    }
    public float GetRandomNumber(float minimum, float maximum)
    {
        return Random.Range(minimum, maximum);
    }

}

public enum typeOfBirth
{
    coin,point,monster
}
